package com.xjm_cloud_admin.controller;

import com.xjm_cloud_admin.annotation.Anonymous;
import com.xjm_cloud_admin.domain.vo.req.SaveShareReqVo;
import com.xjm_cloud_admin.domain.vo.req.ShareCheckReqVo;
import com.xjm_cloud_admin.domain.vo.req.ShareDeleteReqVo;
import com.xjm_cloud_admin.domain.vo.req.ShareFileListReqVo;
import com.xjm_cloud_admin.service.XjmShareService;
import com.xjm_cloud_admin.util.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;

/**
 * 文件分享表(XjmShare)表控制层
 *
 * @author 浪漫写尽歌谱
 * @since 2024-04-23 18:32:32
 */
@RestController
@RequestMapping("share")
public class XjmShareController {
    /**
     * 服务对象
     */
    @Resource
    private XjmShareService xjmShareService;


    /**
     * 新增分享
     *
     * @param saveShareReqVo 分享信息
     * @return 结果
     */
    @PostMapping("insert")
    public R insertShare(@Valid @RequestBody SaveShareReqVo saveShareReqVo) {
        return xjmShareService.insertShare(saveShareReqVo);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param shareId 分享id
     * @return 分享文件信息
     */
    @Anonymous
    @GetMapping("info/{shareId}")
    public R getShareInfo(@Valid @PathVariable String shareId) {
        return xjmShareService.getByShareId(shareId);
    }

    /**
     * 校验密码
     *
     * @param vo 校验信息
     * @return 校验结果
     */
    @Anonymous
    @PostMapping("check")
    public R checkPassword(@Valid @RequestBody ShareCheckReqVo vo) {
        return xjmShareService.checkPassword(vo);
    }

    /**
     * 获取分享的文件
     *
     * @param httpServletRequest 请求
     * @return 文件
     */
    @Anonymous
    @GetMapping("file_list")
    public R fileList(HttpServletRequest httpServletRequest, ShareFileListReqVo vo) {
        return xjmShareService.list(httpServletRequest, vo);
    }

    /**
     * 获取分享列表
     *
     * @return 文件
     */
    @GetMapping("list")
    public R list() {
        return xjmShareService.shareList();
    }

    /**
     * 删除分享
     *
     * @return 结果
     */
    @PostMapping("delete")
    public R delete(@RequestBody @Valid ShareDeleteReqVo vo) {
        return xjmShareService.delete(vo);
    }

}


